<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="收入编号" prop="profitNum">
        <el-input
          v-model="queryParams.profitNum"
          placeholder="请输入收入编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="平台id" prop="disPlatformId">
        <el-input
          v-model="queryParams.disPlatformId"
          placeholder="请输入平台id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="获取分润用户id" prop="disGetUserId">
        <el-input
          v-model="queryParams.disGetUserId"
          placeholder="请输入获取分润用户id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分享分润用户id" prop="disSetUserId">
        <el-input
          v-model="queryParams.disSetUserId"
          placeholder="请输入分享分润用户id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账户类型" prop="accountType">
        <el-select v-model="queryParams.accountType" placeholder="请选择账户类型" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="会员类型" prop="disUserType">
        <el-select v-model="queryParams.disUserType" placeholder="请选择会员类型" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="对应第三方订单编号" prop="disOrderId">
        <el-input
          v-model="queryParams.disOrderId"
          placeholder="请输入对应第三方订单编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="添加时间" prop="addTime">
        <el-input
          v-model="queryParams.addTime"
          placeholder="请输入对应第三方订单编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分类" prop="identityType">
        <el-select v-model="queryParams.identityType" placeholder="请选择分类" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['distribution:record:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="recordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="交易类型交易后金额" align="center" prop="id" />
      <el-table-column label="收入编号" align="center" prop="profitNum" />
      <el-table-column label="收入编号" align="center" prop="disPlatformId" />
      <el-table-column label="收入编号" align="center" prop="disGetUserId" />
      <el-table-column label="收入编号" align="center" prop="disSetUserId" />
      <el-table-column label="收入编号" align="center" prop="disAmount" />
      <el-table-column label="账户类型" align="center" prop="accountType" />
      <el-table-column label="备注" align="center" prop="disNote" />
      <el-table-column label="备注" align="center" prop="disUserType" />
      <el-table-column label="对应第三方订单编号" align="center" prop="disOrderId" />
      <el-table-column label="对应第三方订单编号" align="center" prop="isDelete" />
      <el-table-column label="对应第三方订单编号" align="center" prop="addTime" />
      <el-table-column label="分类" align="center" prop="identityType" />
      <el-table-column label="交易前金额" align="center" prop="beforeAmount" />
      <el-table-column label="交易后金额" align="center" prop="afterAmount" />
      <el-table-column label="交易类型交易前金额" align="center" prop="beforeProAmount" />
      <el-table-column label="交易类型交易后金额" align="center" prop="afterProAmount" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改分润记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="收入编号" prop="profitNum">
          <el-input v-model="form.profitNum" placeholder="请输入收入编号" />
        </el-form-item>
        <el-form-item label="收入编号" prop="disPlatformId">
          <el-input v-model="form.disPlatformId" placeholder="请输入收入编号" />
        </el-form-item>
        <el-form-item label="收入编号" prop="disGetUserId">
          <el-input v-model="form.disGetUserId" placeholder="请输入收入编号" />
        </el-form-item>
        <el-form-item label="收入编号" prop="disSetUserId">
          <el-input v-model="form.disSetUserId" placeholder="请输入收入编号" />
        </el-form-item>
        <el-form-item label="收入编号" prop="disAmount">
          <el-input v-model="form.disAmount" placeholder="请输入收入编号" />
        </el-form-item>
        <el-form-item label="账户类型" prop="accountType">
          <el-select v-model="form.accountType" placeholder="请选择账户类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="disNote">
          <el-input v-model="form.disNote" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="备注" prop="disUserType">
          <el-select v-model="form.disUserType" placeholder="请选择备注">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="对应第三方订单编号" prop="disOrderId">
          <el-input v-model="form.disOrderId" placeholder="请输入对应第三方订单编号" />
        </el-form-item>
        <el-form-item label="对应第三方订单编号" prop="isDelete">
          <el-input v-model="form.isDelete" placeholder="请输入对应第三方订单编号" />
        </el-form-item>
        <el-form-item label="对应第三方订单编号" prop="addTime">
          <el-input v-model="form.addTime" placeholder="请输入对应第三方订单编号" />
        </el-form-item>
        <el-form-item label="分类" prop="identityType">
          <el-select v-model="form.identityType" placeholder="请选择分类">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="交易前金额" prop="beforeAmount">
          <el-input v-model="form.beforeAmount" placeholder="请输入交易前金额" />
        </el-form-item>
        <el-form-item label="交易后金额" prop="afterAmount">
          <el-input v-model="form.afterAmount" placeholder="请输入交易后金额" />
        </el-form-item>
        <el-form-item label="交易类型交易前金额" prop="beforeProAmount">
          <el-input v-model="form.beforeProAmount" placeholder="请输入交易类型交易前金额" />
        </el-form-item>
        <el-form-item label="交易类型交易后金额" prop="afterProAmount">
          <el-input v-model="form.afterProAmount" placeholder="请输入交易类型交易后金额" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRecord, getRecord, delRecord, addRecord, updateRecord, exportRecord } from "@/api/distribution/record";

export default {
  name: "Record",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 分润记录表格数据
      recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        profitNum: null,
        disPlatformId: null,
        disGetUserId: null,
        disSetUserId: null,
        disAmount: null,
        accountType: null,
        disNote: null,
        disUserType: null,
        disOrderId: null,
        isDelete: null,
        addTime: null,
        identityType: null,
        beforeAmount: null,
        afterAmount: null,
        beforeProAmount: null,
        afterProAmount: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询分润记录列表 */
    getList() {
      this.loading = true;
      listRecord(this.queryParams).then(response => {
        this.recordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        profitNum: null,
        disPlatformId: null,
        disGetUserId: null,
        disSetUserId: null,
        disAmount: null,
        accountType: null,
        disNote: null,
        disUserType: null,
        disOrderId: null,
        isDelete: null,
        addTime: null,
        updateTime: null,
        identityType: null,
        beforeAmount: null,
        afterAmount: null,
        beforeProAmount: null,
        afterProAmount: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加分润记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRecord(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改分润记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRecord(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRecord(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除分润记录编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delRecord(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有分润记录数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportRecord(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
